<template>
  <div class="app-container">
    <el-form class="search-form" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
      label-width="68px">
      <!-- <el-form-item label="ID" prop="quaninfoId">
        <el-input v-model="queryParams.quaninfoId" placeholder="请输入定量信息ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="哈希地址" prop="quaninfoHashaddr">
        <el-input v-model="queryParams.quaninfoHashaddr" placeholder="请输入定量信息哈希地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="信息状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择信息状态" clearable>
          <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['truth:quanInfo:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['truth:quanInfo:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['truth:quanInfo:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['truth:quanInfo:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="quanInfoList" @selection-change="handleSelectionChange" :fit="true">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="ID" width="40" align="center" prop="quaninfoId" />
      <!-- <el-table-column label="企业用户id" align="center" prop="comUserid" /> -->
      <el-table-column label="销售利润率" width="100" align="center" prop="comRos" />
      <el-table-column label="净资产收益率" width="100" align="center" prop="comRoe" />
      <el-table-column label="总资产收益率" width="100" align="center" prop="comRota" />
      <el-table-column label="销售增长率" width="100" align="center" prop="comSgrow" />
      <el-table-column label="销售利润增长率" width="130" align="center" prop="comGagr" />
      <el-table-column label="总资产增长率" width="100" align="center" prop="comTagr" />
      <el-table-column label="速动比率" width="100" align="center" prop="comQr" />
      <el-table-column label="资产负债率" width="100" align="center" prop="comAr" />
      <el-table-column label="现金流动负债比率" width="130" align="center" prop="comAto" />
      <el-table-column label="总资产周转率" width="100" align="center" prop="comItr" />
      <el-table-column label="应收账款周转率" width="130" align="center" prop="comCat" />
      <el-table-column label="流动资产周转率" width="130" align="center" prop="comIto" />
      <el-table-column label="存货周转比率" width="100" align="center" prop="comIte" />
      <el-table-column label="定量信息hash地址" width="200" align="center" prop="quaninfoHashaddr" />
      <el-table-column label="信息状态" width="100" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" width="100" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="110" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['truth:quanInfo:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['truth:quanInfo:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改企业经营数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="720px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" inline>
        <!--  <el-form-item label="企业用户id" prop="comUserid">
          <el-input v-model="form.comUserid" placeholder="请输入企业用户id" />
        </el-form-item> -->
        <el-form-item label="销售利润率" prop="comRos">
          <el-input v-model="form.comRos" placeholder="请输入销售利润率" />
        </el-form-item>
        <el-form-item label="净资产收益率" prop="comRoe">
          <el-input v-model="form.comRoe" placeholder="请输入净资产收益率" />
        </el-form-item>
        <el-form-item label="总资产收益率" prop="comRota">
          <el-input v-model="form.comRota" placeholder="请输入总资产收益率" />
        </el-form-item>
        <el-form-item label="销售增长率" prop="comSgrow">
          <el-input v-model="form.comSgrow" placeholder="请输入销售增长率" />
        </el-form-item>
        <el-form-item label="销售利润增长率" prop="comGagr">
          <el-input v-model="form.comGagr" placeholder="请输入销售利润增长率" />
        </el-form-item>
        <el-form-item label="总资产增长率" prop="comTagr">
          <el-input v-model="form.comTagr" placeholder="请输入总资产增长率" />
        </el-form-item>
        <el-form-item label="速动比率" prop="comQr">
          <el-input v-model="form.comQr" placeholder="请输入速动比率" />
        </el-form-item>
        <el-form-item label="资产负债率" prop="comAr">
          <el-input v-model="form.comAr" placeholder="请输入资产负债率" />
        </el-form-item>
        <el-form-item label="现金流动负债比率" prop="comAto">
          <el-input v-model="form.comAto" placeholder="请输入现金流动负债比率" />
        </el-form-item>
        <el-form-item label="总资产周转率" prop="comItr">
          <el-input v-model="form.comItr" placeholder="请输入总资产周转率" />
        </el-form-item>
        <el-form-item label="应收账款周转率" prop="comCat">
          <el-input v-model="form.comCat" placeholder="请输入应收账款周转率" />
        </el-form-item>
        <el-form-item label="流动资产周转率" prop="comIto">
          <el-input v-model="form.comIto" placeholder="请输入流动资产周转率" />
        </el-form-item>
        <el-form-item label="存货周转比率" prop="comIte">
          <el-input v-model="form.comIte" placeholder="请输入存货周转比率" />
        </el-form-item>
        <!--  <el-form-item label="定量信息hash地址" prop="quaninfoHashaddr">
          <el-input v-model="form.quaninfoHashaddr" placeholder="请输入定量信息hash地址" />
        </el-form-item> -->
        <el-form-item label="信息状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{ dict.label
            }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listQuanInfo, getQuanInfo, delQuanInfo, addQuanInfo, updateQuanInfo } from "@/api/truth/quanInfo";

export default {
  name: "QuanInfo",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业经营数据表格数据
      quanInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 信息状态时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        quaninfoId: null,
        comUserid: null,
        comRos: null,
        comRoe: null,
        comRota: null,
        comSgrow: null,
        comGagr: null,
        comTagr: null,
        comQr: null,
        comAr: null,
        comAto: null,
        comItr: null,
        comCat: null,
        comIto: null,
        comIte: null,
        quaninfoHashaddr: null,
        status: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    console.log(document.querySelector('thead'));
  },
  methods: {
    /** 查询企业经营数据列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listQuanInfo(this.queryParams).then(response => {
        this.quanInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        quaninfoId: null,
        comUserid: null,
        comRos: null,
        comRoe: null,
        comRota: null,
        comSgrow: null,
        comGagr: null,
        comTagr: null,
        comQr: null,
        comAr: null,
        comAto: null,
        comItr: null,
        comCat: null,
        comIto: null,
        comIte: null,
        quaninfoHashaddr: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.quaninfoId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业经营数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const quaninfoId = row.quaninfoId || this.ids
      getQuanInfo(quaninfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业经营数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.quaninfoId != null) {
            updateQuanInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQuanInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const quaninfoIds = row.quaninfoId || this.ids;
      this.$modal.confirm('是否确认删除企业经营数据编号为"' + quaninfoIds + '"的数据项？').then(function () {
        return delQuanInfo(quaninfoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('truth/quanInfo/export', {
        ...this.queryParams
      }, `quanInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped >
@import url('../../../../theme/search-form.css');

/deep/ .el-dialog {
  width: 720px;
}

/deep/.el-dialog__body .el-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .el-form-item {
    width: 48%;
    margin-right: 0 !important;
    display: flex;
    justify-content: space-between;

    /* &:nth-child(old) {
      margin-right: 10px;
    } */

    .el-form-item__label {
      width: 40%;
      text-align: left;
    }

    .el-radio-group {
      width: 206px;
    }
  }
}
</style>
